import requests

# 打开首页
r = requests.get('http://localhost/agileone/index.php')
cookie = r.cookies
# print(cookie)

# http://localhost/agileone/index.php/common/login?username=admin&password=admin&savelogin=true
# 登陆
data = 'username=admin&password=admin&savelogin=true'
# data = {'username':'admin', 'password':'admin','savelogin':'true'}
headers = {'Content-Type': 'application/x-www-form-urlencoded'}
r = requests.post('http://localhost/agileone/index.php/common/login', data=data, headers=headers, cookies=cookie)
print(r.text)
# print(r.cookies)

# 新增公告
# data = 'headline=title&content=content&scope=a.txt&expireddate=2019-02-16'
# headers = {'Content-Type': 'application/x-www-form-urlencoded'}
# r = requests.post('http://localhost/agileone/index.php/notice/add', data=data, headers=headers, cookies = cookie)
# print(r.text)
# print(r.cookies)

# #优化
# s = requests.session()  #建立会话对象, 它可以跨请求保持参数. 换言之: 它会在同一个Session对象发出的所有请求之间保持cookie. 带来性能提升.
# r = s.get('http://localhost/agileone/index.php')
# # print(r.cookies)
#
# data = 'username=admin&password=admin&savelogin=true'
# headers = {'Content-Type': 'application/x-www-form-urlencoded'}
# r = s.post('http://localhost/agileone/index.php/common/login', data=data, headers=headers)
# print(r.text)
# # print(r.cookies)
#
# data = 'headline=title&content=content&scope=a.txt&expireddate=2019-02-16'
# headers = {'Content-Type': 'application/x-www-form-urlencoded'}
# r = s.post('http://localhost/agileone/index.php/notice/add', data=data, headers=headers)
# print(r.text)
# # print(r.cookies)
#
# data = 'currentpage=a.txt'
# headers = {'Content-Type': 'application/x-www-form-urlencoded'}
# r = s.post('http://localhost/agileone/index.php/notice/query', data=data, headers=headers)
# content = r.json()
# print(content[0]['createdtime'])
